package org.finesys.common.security.core.fegin;

import feign.RequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.server.resource.web.BearerTokenResolver;

@Configuration
@ConditionalOnProperty(name = "feign.enabled", havingValue = "true")
public class AuthFeignClientConfiguration {
    /**
     * 注入 oauth2 feign token 增强
     *
     * @param bearerTokenResolver token获取处理器
     * @return 拦截器
     */
    @Bean
    RequestInterceptor authRequestInterceptor(BearerTokenResolver bearerTokenResolver) {
        return new AuthRequestInterceptor(bearerTokenResolver);
    }
}
